package com.jeasonzhao.commons.data;

public class Row<CELL extends Cell> extends java.util.Vector<CELL>
{
    private static final long serialVersionUID = 1L;
    private RowTypes rowType = RowTypes.Body;
    private int rowIndex = 0;
    public Row()
    {
        super();
    }

    public Row(int size)
    {
        super(size);
    }

    public Row(Iterable<CELL> cells)
    {
        if(null == cells)
        {
            return;
        }
        if(cells instanceof Row)
        {
            copyFrom((Row<CELL>) cells);
        }
        else
        {
            for(java.util.Iterator<CELL> it = cells.iterator();it.hasNext();)
            {
                CELL c = it.next();
                this.add(c);
            }
        }
    }

    public Row(Iterable<CELL> cells,boolean cleanSpans,boolean visible)
    {
        this(cells);
        for(CELL c : this)
        {
            if(cleanSpans)
            {
                c.cleanSpans();
            }
            c.setVisible(visible);
        }
    }

    public Row<CELL> add(CELL ...cells)
    {
        if(null == cells)
        {
            return this;
        }
        else
        {
            for(CELL c : cells)
            {
                this.add(c);
            }
        }
        return this;
    }

    private void copyFrom(Row<CELL> row)
    {
        if(null == row)
        {
            return;
        }
        this.rowIndex = row.rowIndex;
        this.rowType = row.rowType;
        this.clear();
        for(CELL c : row)
        {
            this.add(c);
        }
    }

    public int hashCode()
    {
        return super.hashCode();
    }

    public boolean equals(Object obj)
    {
        return super.equals(obj);
    }

    public int getRowIndex()
    {
        return rowIndex;
    }

    public RowTypes getRowType()
    {
        return rowType;
    }

    public Row<CELL> setRowIndex(int rowIndex)
    {
        this.rowIndex = rowIndex;
        return this;
    }

    public Row<CELL> setRowType(RowTypes rowType)
    {
        this.rowType = rowType;
        return this;
    }

}
